/**
 * 
 */
package com.network.entity;

import java.util.Collection;

import org.springframework.stereotype.Component;

import com.network.cfg.Configuration;

/**
 * @author Ling xiaowei
 * 
 */
@Component
public class Page {

	private Integer pageNo; // 当前页号
	private Integer pageSize; // 每页记录条数
	private Collection content; // 本页记录集
	private int totalRecNum; // 总记录条数
//	private Integer totalPageNum; // 总页面数量
//	private Boolean prePage; // 是否有上一页
//	private Boolean nextPage; // 是否有下一页
//	private Integer startIndex; // 本页记录开始编号
//	private Integer endIndex; // 本页记录结束编号
	
	public Page(Integer pageNo)
	{
		super();
		this.pageNo = pageNo;
		this.pageSize = Configuration.PAGE_SIZE;
	}
	
    public Page()
    {
    	this(1);
    }

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Collection getContent() {
		return content;
	}

	public void setContent(Collection content) {
		this.content = content;
	}

	public int getTotalRecNum() {
		return totalRecNum;
	}

	public void setTotalRecNum(int totalRecNum) {
		this.totalRecNum = totalRecNum;
	}

	public Integer getTotalPageNum() {
		return totalRecNum%pageSize!=0?(int)(totalRecNum/pageSize+1):(int)(totalRecNum/pageSize);
	}

	public Boolean hasPrePage() {
		return pageNo>1;
	}

	public Boolean hasNextPage() {
		return pageNo<this.getTotalPageNum();
	}
	
	public int getPrePage()
	{
		if(hasPrePage())
		{
			return pageNo - 1;
		}
		else
		{
			return pageNo;
		}
	}
	
	public int getNextPage()
	{
		if(hasNextPage())
		{
			return pageNo + 1;
		}
		else
		{
			return pageNo;
		}
	}

	public int getStartIndex() {
		return pageSize*(pageNo-1);
	}

	public int getEndIndex() {
		return pageSize*pageNo>this.getTotalRecNum()?this.getTotalRecNum():pageSize*pageNo;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return new String("PageNo:"+this.getPageNo()+" Total:"+this.getTotalRecNum()+" Start:"+this.getStartIndex());
	}


}
